<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/6
 * Time: 15:00
 */
namespace app\modules\api\controllers;
use app\models\TencentLive;
use app\modules\api\models\TencentLiveForm;
class TencentLiveController extends Controller
{
    public function actionSave()
    {
          $res = \Yii::$app->request->get();
          $store_id = $res['store_id'];
          $roomid = $res['roomid'];
          $is_open = $res['is_open'];
          $model = TencentLive::findOne(['store_id'=>$store_id,'roomid'=>$roomid]);
//          var_dump($model);
//          exit();
          if(!$model){
              $model = new TencentLive();
          }
          if(\Yii::$app->request->isGet){
              $form = new TencentLiveForm();
              $form->attributes = \Yii::$app->request->get();
              $form->model = $model;
              return $this->renderJson($form->save());
          }
    }
    public function actionData()
    {
        $res = TencentLive::find()->where(['store_id'=>$this->store_id,'is_open'=>1])->select('roomid')->asArray()->all();
        $roomid = $res[0]['roomid'];
        return $this->renderJson($roomid);

    }
}